﻿@using QLNS
@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_Home.cshtml";
    PhongBan pb = ViewBag.PhongBan;
}

<script type="text/javascript">
    $(document).ready(function () {
        // prepare the data
        var source =
            {
                datatype: "json",
                datafields: [
                     { name: 'ID' },
					 { name: 'SoHieuCBCC' },
                     { name: 'Ho' },
                     { name: 'Ten' },
                     { name: 'TenChucVuHienTai' },
                     { name: 'NgaySinh', type: 'date' },
                     { name: 'GioiTinh' },
                     { name: 'HoKhauThuongTru' },
                     { name: 'DiaChi' }

                ],
                id: 'ID',
                url: '/Pers/GetListPersonsInDepartmentInclude/@pb.ID/',
                root: 'Rows',
                sort: function () {
                    // update the grid and send a request to the server.
                    $("#jqxgridcontent").jqxGrid('updatebounddata', 'sort');
                }

            };

        var dataAdapter = new $.jqx.dataAdapter(source,
                {
                    downloadComplete: function (data) {
                        source.totalrecords = data.TotalRows;
                    }
                }
            );

        // initialize jqxGrid
        $("#jqxgridcontent").jqxGrid(
            {
                width: '100%',
                source: dataAdapter,
                theme: 'darkblue',
                columnsresize: true,
                autoheight: true,
                pageable: true,
                virtualmode: true,
                sortable: true,
                rendergridrows: function (params) {
                    return params.data;
                },
                ready: function () {
                    $("#jqxgridcontent").jqxGrid('hidecolumn', 'ID');
                    //$('#jqxgridcontent').jqxGrid('autoresizecolumns'); 
                     @{ if (Session["Quyen"].ToString() == "2")
                       {
                           @(new HtmlString("$('#jqxgridcontent').jqxGrid('hidecolumn', 'Delete');"))
                           @(new HtmlString("$('#jqxgridcontent').jqxGrid('hidecolumn', 'Edit');"))
                       }
                     }
                },
                columns:
                 [
                      { text: 'ID', editable: false, datafield: 'ID', width: 0 },
                     // { text: 'IDLyLuan', datafield: 'IDLyLuan', width: 0 },
                      {text: 'Số hiệu', datafield: 'SoHieuCBCC', width: '80px' },
                      { text: 'Họ', datafield: 'Ho', width: '15%' },
                       { text: 'Tên', datafield: 'Ten', width: '7%' },
                       { text: 'Chức Vụ', datafield: 'TenChucVuHienTai', width: '120px' },
                      { text: 'Ngày sinh', datafield: 'NgaySinh', cellsformat: 'dd-MM-yyyy', width: '80px' },
                      { text: 'Giới tính', datafield: 'GioiTinh', width: '40px' },
                      { text: 'Hộ khẩu thường trú', datafield: 'HoKhauThuongTru', width: '20%' },
                      { text: 'Địa chỉ', datafield: 'DiaChi', width: '20%' },
                      { text: 'Del', datafield: 'Delete', columntype: 'button', pinned: true, width: '26px',
                          cellsrenderer: function () {
                              return "Delete"
                          },

                          buttonclick: function (row) {
                              // open the popup window when the user clicks a button.
                              editrow = row;

                              var dataRecord = $("#jqxgridcontent").jqxGrid('getrowdata', editrow);
                              document.location.href = '/Pers/Delete/' + dataRecord.ID + '/';


                          }
                      },

                      { text: 'Edit', datafield: 'Edit', columntype: 'button', pinned: true, width: '26px',
                          cellsrenderer: function () {
                              return "Edit"
                          },

                          buttonclick: function (row) {
                              // open the popup window when the user clicks a button.
                              editrow = row;

                              var dataRecord = $("#jqxgridcontent").jqxGrid('getrowdata', editrow);
                              document.location.href = '/Pers/Update/' + dataRecord.ID + '/';


                          }
                      }

                  ]
            });
            //auto resize grid
                  
                  
    });
    </script>


<div class="toolbar">
<ul>
    <li><input class="tbtnBack" type="button" value="Quay về" onclick="javascript:history.back()"/>
    </li>
     @{ if (Session["Quyen"].ToString() == "1")
        {
    <li><input class="tbtnAdd" type="button" value="Thêm mới" onclick="javascript:window.location='/Pers/Add/@pb.ID'"/>
    </li>}}
    <li><input class="tbtnReport" type="button" value="In" onclick="javascript:window.location='/aspFrm/frmDanhSachCanBoPhongBanInclude.aspx?id=@pb.ID'"/>
    </li>
</ul>
<div class="ttitle">Danh sách cán bộ @pb.TenPhongBan</div>
</div>
<div id="jqxgridcontent"></div>

